
<meta charset="utf-8" />

	<form class="form-horizontal" >
	<table id="dialog-grid-table"></table>
	
	
	<div class="form-actions align-right  form-button-box" style="margin-top: 0px">
		<button class="btn btn-info" type="button"  onclick="addMenu(this);">
			<!-- <i class="ace-icon fa fa-check bigger-110"></i>  auth="auth/menuManage/add.do" -->保存
		</button>

		&nbsp; 
		<button class="btn" type="button" onclick="javascript:dialog.close(this);">
			 关闭
		</button>
	</div>
	</form>	



<script type="text/javascript">

	
	jQuery(function($) {	
		var dialog_grid_selector = "#dialog-grid-table";
		var $dialogBox = dialog.getByChildren(dialog_grid_selector);
		
		$($dialogBox).on('resize.dialog.jqGrid', function () {
			$(dialog_grid_selector).jqGrid( 'setGridWidth',$dialogBox.width() );
	    });
		var parent_column = $(dialog_grid_selector).closest('[class*="col-"]');
		$(document).on('settings.ace.jqGrid' , function(ev, event_name, collapsed) {
			if( event_name === 'sidebar_collapsed' || event_name === 'main_container_fixed' ) {
				setTimeout(function() {
					$(grid_selector).jqGrid( 'setGridWidth', parent_column.width());
				}, 0);
			}
	    })
		var p = dialog.getById('dlg-menuadd');
		jQuery(dialog_grid_selector).jqGrid({
			url: "auth/menuAdd/init.do?menuId="+p.dataParam.menuId+"&sysId="+p.dataParam.sysId,
			datatype: "json",
			height: "100%",
			width:'80%',
		    colNames:[  '所属系统','上级菜单','菜单名称','菜单路径'],
			colModel:[
				{name:'sysId',    index:'sysId',     width:'110px', formatter : sysIdFormat},
				{name:'rmk',        index:'rmk',     width:'100px'},
				{name:'menuName',   index:'menuName',   width:'200px', formatter : menuNameFormat},
				{name:'menuUrl',    index:'menuUrl',    width:'205px', formatter : menuUrlFormat}
			], 
			viewrecords : true,
			rowNum:10,
			rowList:[10,20],
			altRows: true,
			shrinkToFit:false,
			multiselect: false,
	        multiboxonly: true,
	        loadComplete : function() {
				var table = this;
				setTimeout(function(){
					 //加载分页
					 //initPagingBar(grid_selector);
				}, 0);
			},
			beforeRequest:function(){//请求之前执行
				
			},
			gridComplete: function () {//隐藏表头
                $(this).closest('.ui-jqgrid-view').find('div.ui-jqgrid-hdiv').hide();
                $dialogBox.trigger("resize");
                //下拉框重新渲染
                $("select[location]",$(dialog_grid_selector)).selLoad();
            },
	
		});
		//<input type='text' ></input>
		function menuNameFormat(cellvalue, options, rowObject){
 			return "<input type='text' id='menuName_"+options.rowId+"' placeholder='请输入菜单名称' style='width:200px'></input>";
		}
		function menuUrlFormat(cellvalue, options, rowObject){
 			return "<input type='text' id='menuUrl_"+options.rowId+"' placeholder='请输入菜单地址' style='width:350px'></input>";
		}
		function sysIdFormat(cellvalue, options, rowObject){
			return DICT.get("SYSTYPE", rowObject.sysId);
		}

		
		$($dialogBox).triggerHandler('resize.dialog.jqGrid');//trigger window resize to make the grid get the correct size
		$($dialogBox).one('ajaxloadstart.page', function(e) {
			$(grid_selector).jqGrid('GridUnload');
			$('.ui-jqdialog').remove();
		});
		
	});
	
	
	
	function addMenu(obj){
		var count = $("#dialog-grid-table").getGridParam("reccount");
		var p = dialog.getById('dlg-menuadd');
		var jsonData = new Array();
		for (var i = 1; i <= count; i++) {
			if(($("#menuName_"+i).val()) !=null && ($("#menuName_"+i).val()) != ""){
			    var jsonMenu = {}; 
			    jsonMenu["menuName"]=$("#menuName_"+i).val();
			    jsonMenu["menuUrl"]=$("#menuUrl_"+i).val();
			    jsonMenu["menuStatus"]=0;
			    jsonMenu["menuType"]=0;
			    jsonMenu["menuParId"]=p.dataParam.menuId;
			    jsonMenu["sysId"]=p.dataParam.sysId;
	            jsonData.push(jsonMenu);
			}

		}
		if(jsonData.length == 0){
			msg.alert("警告", "没有要提交的数据！", 'warn');
			return;
		}
		 $.ajax({
		       url:'auth/menuAdd/add.do', 
		       type:'post',         
		       dataType:'json',    
		       contentType:"application/json",
		       data:JSON.stringify(jsonData),        
		       success : function(result) {
					if (result.rspcod != "200") {
						$msg.alert("错误", result.rspmsg + " 错误代码："
								+ result.rspcod, 'error');
					} else {
						msg.alert("提示", result.rspmsg, 'correct');
						$("#grid-table").trigger("reloadGrid");
						dialog.close(obj);
					}
				},
			  error:function(XMLHttpRequest, textStatus){
				  $msg.alert("错误", textStatus + " 错误代码："
							+ XMLHttpRequest.status, 'error');
				}
		     });
	}
   
</script>

<div class="w-load"><div class="spin"></div></div>
